# Set the working directory to the project folder.
project_folder <- "."
setwd(project_folder)
# Load packages
library(Seurat)
library(ggplot2)
library(grid)
library(dplyr)
# Set colors Establecer los colores utilizados en las visualizaciones
cols2 <- c(`0 CD8+ Eff mem (EM)` = "#A6CEE3", `1 CD8+ Eff cytotox (Ecyt)` = "#1F78B4",
`2 Early prolif: HMGN+/HMGB+/PCNA+ cells` = "#FDBF6F", `3 CD4+ Naive/SCM` = "#33A02C",
`4 Early prolif: MCM3/5/7+ PCNA+ cells` = "#FB9A99", `5 Late prolif: histones enriched MKI67+ cells` = "#E31A1C",
`6 CD4+ Central/Effector memory (CM/EM)` = "#B2DF8A", `7 Ribosomal/Mitocondrial/Degradated cells` = "#FF7F00",
`8 Late prolif: CDK+/CDC+/AURKA+ MIK67+ cells` = "#CAB2D6", `9 Tcells` = "#6A3D9A")
cols3 <- c(`CAR+` = "#66c2a5", `CAR-` = "#fc8d62")
cols4 <- c("#264653", "#2a9d8f", "#e9c46a", "#f4a261", "#e76f51")
cols5 <- c(IP = "#4E6AAB", Peak = "#e78ac3")
cols6 <- c(CD4 = "#147D2C", CD8 = "#F5C936", Unknown = "#7f7f7f")
cols7 <- c(G1 = "#F8766D", G2M = "#00BA38", S = "#619CFF")
cols8 <- c("#E69F00FF", "#56B4E9FF", "#009E73FF", "#F0E442FF")
scCARTseq
integrated.obj <- readRDS("integrated.obj.rds")
UMAPS
integrated.obj$umap1 <- integrated.obj@reductions$umap@cell.embeddings[, 1]
integrated.obj$umap2 <- integrated.obj@reductions$umap@cell.embeddings[, 2]
aux_df1 <- data.frame(umap1 = integrated.obj$umap1, umap2 = integrated.obj$umap2,
Clusters = Idents(integrated.obj), integrated.obj[[]])
Totalcells <- nrow(aux_df1)
grob <- grobTree(textGrob(paste0("n = ", Totalcells), x = 0.05, y = 0.95, hjust = 0,
gp = gpar(fontsize = 12)))
ggplot(aux_df1, aes(umap1, umap2)) + geom_point(aes(color = Clusters), size = 0.9) +
theme_classic() + guides(colour = guide_legend(override.aes = list(size = 3))) +
scale_color_manual(values = cols2) + annotation_custom(grob)

ggplot(aux_df1, aes(umap1, umap2)) + geom_point(aes(color = Clusters), size = 0.9) +
theme_classic() + theme(legend.position = "none") + scale_color_manual(values = cols2) +
facet_grid(~Patient_id)

# CAR +/-
aux_df1 <- aux_df1[order(aux_df1$Class1, decreasing = TRUE), ]
ggplot(aux_df1, aes(umap1, umap2)) + geom_point(aes(color = Class1), size = 0.9) +
theme_classic() + guides(colour = guide_legend(override.aes = list(size = 3))) +
scale_color_manual(values = cols3) + annotation_custom(grob)

# Peak/ IP
ggplot(aux_df1, aes(umap1, umap2)) + geom_point(aes(color = Timepoint), size = 0.9) +
theme_classic() + guides(colour = guide_legend(override.aes = list(size = 3))) +
scale_color_manual(values = cols5) + annotation_custom(grob)

# Patient
ggplot(aux_df1, aes(umap1, umap2)) + geom_point(aes(color = Patient_id), size = 0.9) +
theme_classic() + guides(colour = guide_legend(override.aes = list(size = 3))) +
scale_color_manual(values = cols4) + annotation_custom(grob)
